<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
/*
industry_list = [
  {
     "parent_ind" : "女装",
     "name" : "连衣裙"
  },
  {
     "name": "女装"
  },
  {
     "parent_ind" : "女装",
     "name" : "半身裙"
  },
  {
     "parent_ind" : "女装",
     "name" : "A字裙"
  },
  {
     "name": "数码"
  },
  {
    "parent_ind" : "数码",
     "name": "电脑配件"
  },
  {
    "parent_ind" : "电脑配件",
     "name": "内存"
  },
]
实现一个方法完成这个转换
def convert_format(data)
{
  "数码": {
    "电脑配件": {
        "内存" : {}
     }
  },
  "女装" : {
     "连衣裙": {},
    "半身裙": {},
    "A字裙": {}
  }
}

*/
        var industry_list = [
            {
            "parent_int":"女装",
            "name":"连衣裙"
            },
            {
            "name":"女装"
            },
            {
            "parent_int":"女装",
            "name":"半身裙"
            },
            {
            "parent_int":"女装",
            "name":"A字群"
            },
            {
            "name":"数码"
            },
            {
            "parent_int":"数码",
            "name":"电脑配件"
            },
            {
            "parent_int":"电脑配件",
            "name":"内存"
            } 
        ]
        let newObj = {}
        let names = []
        let newArr = []
        function convert_format(data){
            if(Array.isArray(data)){
                for(let i in data){
                    let obj = data[i]
                    if (!obj.hasOwnProperty("parent_int")){
                        names.push(obj.name)
                        newObj[obj.name] = {}
                    }else{
                        newArr.push(obj)
                    }
                }
            }
          
        //    for(let j in newArr){
                names.forEach((name)=>{
                    childrenArr(newArr,name)
                    // if(newArr[j].parent_int===name){
                    //     newObj[name][newArr[j].name] = {}
                    // }
                })
               
        //    }
          
            return newObj
           
        }

        function childrenArr(newArr,name){
            console.log(newArr);
            console.log(name);
            for(let j in newArr){
                if(newArr[j].parent_int===name){
                        newObj[name][newArr[j].name] = {}
                    }else{
                        console.log("--------");
                        console.log(newArr[j].parent_int+",,,,"+newArr[j].name);
                        console.log(name);
                        childrenArr[newArr,newArr[j].name]
                        // newObj[name][childrenArr[newArr,newArr[j].parent_int]] = {}
                    }
           }
           console.log(newObj);
           return newObj
        }
        console.log(convert_format(industry_list));

    </script>
</body>
</html>